<?php

namespace App\Entities\Auth;

use App\Libraries\Entities\BaseEntity;

class Role extends BaseEntity
{
    public $timestamps = true;
    protected $StatusFlag = true;
    protected $DescriptionFlag = true;
    protected $SortFlag = true;
    protected $table = 'auth_roles';
    public $primaryKey = 'role_id';
    protected $fillable = [
        'organize_id',
        'category',
        'encode',
        'name',
        'is_public',
        'overdue_time',
    ];

    protected $casts = [
        'status' => 'boolean',
        'is_public' => 'boolean',
    ];

    /**
     * 模块权限.
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function moduleAuthorize()
    {
        return $this->morphToMany(Module::class, 'categorytable', 'auth_authorizes', 'categorytable_id', 'itemtable_id');
    }

    /**
     * 模块按钮权限.
     *
     * @return void
     */
    public function moduleButtonAuthorize()
    {
        return $this->morphToMany(ModuleButton::class, 'categorytable', 'auth_authorizes', 'categorytable_id', 'itemtable_id');
    }

    /**
     * 拥有该角色的用户.
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function users()
    {
        return $this->morphToMany(Manager::class, 'categorytable', 'auth_user_relations', 'categorytable_id', 'user_id');
    }
}
